#ifndef FRAME_H
#define FRAME_H
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/line_descriptor.hpp>
#include "Eigen/Core"
#include "Eigen/Geometry"
#include "DBoW2/DBoW2/BowVector.h"
#include "DBoW2/DBoW2/FeatureVector.h"
#include "DBoW2/DBoW2/FORB.h"
#include "DBoW2/DBoW2/TemplatedVocabulary.h"

using namespace std;
using namespace Eigen;
namespace Relocation_Slam
{
    typedef DBoW2::TemplatedVocabulary<DBoW2::FORB::TDescriptor, DBoW2::FORB>
            ORBVocabulary;

    class Frame
    {
    public:
        Frame();

        Frame(ORBVocabulary* voc,cv::Mat im,Eigen::Isometry3d pose,double picName);

        // Extract ORB on the image. 0 for left image and 1 for right image.
        void ExtractORB(const cv::Mat &im);

        // Extract LINE on the image
        void ExtractLine(const cv::Mat &im);

        void CombineMapPoints();

        void SetFrameId(int frameid);

        void ComputeBoW();
    public:
        cv::Ptr<cv::FeatureDetector> detector;
        cv::Ptr<cv::DescriptorExtractor> descriptor;

        cv::Ptr<cv::line_descriptor::LSDDetector> bd_line;
        cv::Ptr<cv::line_descriptor::BinaryDescriptor> bd;

        ORBVocabulary* mpORBvocabulary;
        DBoW2::BowVector mBowVec;
        DBoW2::FeatureVector mFeatVec;

        std::vector<cv::KeyPoint> mvKeyPoints; ///< 存储所有的特征点
        std::vector<bool> mbKpTriangle; ///< 每个特征点是否被三角化过
        std::vector<int> mnMappointId; ///< 每个特征点对应地图点在vector中的索引

        vector<vector<cv::Point3f>> mmMapPoints;

        vector<cv::Point3f> mmMapPointsRes;  ///< 融合（没用）
        cv::Mat mPointDescriptors;
        cv::Mat mLineDescriptors;

        // Frame timestamp.
        double mTimeStamp;

        Eigen::Isometry3d mPose;

        vector<Frame*>  mReferenceFrame;

        double mdPicName;

        int mnFrameId;


        // Calibration matrix and OpenCV distortion parameters.
        cv::Mat mK;
        static float fx;
        static float fy;
        static float cx;
        static float cy;
        static float invfx;
        static float invfy;
        cv::Mat mDistCoef;

        cv::Mat image;

    };

}// namespace Relocation_Slam

#endif // FRAME_H
